Skip to content

test: math: port dcblock_math_test CMocka test to ztest - #11468

Open
tmleman wants to merge 1 commit into
thesofproject:mainfrom
tmleman:topic/upstream/pr/ut/ztest/math/dcblock
Open

tmleman wants to merge 1 commit into
thesofproject:mainfrom
tmleman:topic/upstream/pr/ut/ztest/math/dcblock

Conversation

@tmleman

@tmleman tmleman commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Add a ztest suite for the DC-blocking filter's fixed-point math (dcblock_generic.c), covering the same six cases as the CMocka test: passthrough, DC removal convergence, saturation, and bit-exact checks for S32, S16 and S24 sample formats. This closes one of the two "misfiled" math tests identified in the Phase 3 plan (filed under test/cmocka/src/audio/dcblock/ despite testing pure math, not the component), with drc_math_test deferred to Phase 4.

Only dcblock_generic.c and numbers.c are linked, matching the CMocka target's source list. M_PI is not exposed by <math.h> under this toolchain's strict -std=c17 build, so it is defined locally guarded by #ifndef, matching the value already used elsewhere without relying on glibc feature-test macros.

Code coverage testing did not reveal any regression.

CMock stats for dcblock_generic.c

  • lines: 100.0 % (78/78)
  • branches: 67.2 % (39/58)

Ztest stats for dcblock_generic.c

  • lines: 74.0 % (74/100)
  • branches: 60.0 % (24/40)

The ztest denominator is larger because CONFIG_FORMAT_FLOAT=y on native_sim compiles in dcblock_float_default(), an inert float code path that neither framework's test exercises (legacy CMocka scope is integer formats only); the cmocka build never compiles that function in at all. Restricted to the int-format code shared by both builds, coverage is equivalent.

Mutation-tested by dropping the pole term from dcblock_generic()'s difference equation, confirming 5 of 6 cases fail, then reverting. Verified clean under --enable-asan --enable-lsan.

Assisted-by: Copilot:claude-sonnet-5

Copilot AI balanced review requested due to automatic review settings November 16, 2026 13:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The test comment incorrectly describes R = 1 as a pure differentiator, although the recurrence yields passthrough behavior with zero initial state.

1 open issue
What changed in this PR

Ports the DC-blocking filter’s fixed-point math tests from CMocka to Zephyr ztest, advancing SOF’s math-test migration without changing production code.

Changes:

  • Adds six cases covering passthrough, DC removal, saturation, and reference comparisons for S32, S16, and S24 formats.
  • Adds a minimal test target linking dcblock_generic.c and numbers.c.
  • Configures native_sim execution and floating-point diagnostic output.
File Description
test/​ztest/​unit/​math/​dcblock/​testcase.yaml Registers the suite for native_sim.
test/​ztest/​unit/​math/​dcblock/​test_dcblock_ztest.c Implements six tests and reference helpers.
test/​ztest/​unit/​math/​dcblock/​prj.conf Enables ztest and floating-point formatting.
test/​ztest/​unit/​math/​dcblock/​CMakeLists.txt Defines the test target, sources, and dependencies.

Review effort: Balanced

return tail_count ? tail_abs_sum / tail_count : 0.0;
}

/* Passthrough: R = 1.0 gives y[n] = x[n] - x[n-1], a pure differentiator. */
Add a ztest suite for the DC-blocking filter's fixed-point math
(dcblock_generic.c), covering the same six cases as the CMocka test:
passthrough, DC removal convergence, saturation, and bit-exact checks
for S32, S16 and S24 sample formats. This closes one of the two
"misfiled" math tests identified in the Phase 3 plan (filed under
test/cmocka/src/audio/dcblock/ despite testing pure math, not the
component), with drc_math_test deferred to Phase 4.

Only dcblock_generic.c and numbers.c are linked, matching the CMocka
target's source list. M_PI is not exposed by <math.h> under this
toolchain's strict -std=c17 build, so it is defined locally guarded by
#ifndef, matching the value already used elsewhere without relying on
glibc feature-test macros.

Code coverage testing did not reveal any regression.

CMock stats for dcblock_generic.c
- lines: 100.0 % (78/78)
- branches: 67.2 % (39/58)

Ztest stats for dcblock_generic.c
- lines: 74.0 % (74/100)
- branches: 60.0 % (24/40)

The ztest denominator is larger because CONFIG_FORMAT_FLOAT=y on
native_sim compiles in dcblock_float_default(), an inert float code path
that neither framework's test exercises (legacy CMocka scope is integer
formats only); the cmocka build never compiles that function in at all.
Restricted to the int-format code shared by both builds, coverage is
equivalent.

Mutation-tested by dropping the pole term from dcblock_generic()'s
difference equation, confirming 5 of 6 cases fail, then reverting.
Verified clean under --enable-asan --enable-lsan.

Assisted-by: Copilot:claude-sonnet-5
Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.com>
@intel-sofci

Copy link
Copy Markdown

PR 11468: test results

Run date: 2026-11-16 15:52 UTC

Tested commit: 4daf81bc7336d19a46539317ae342db53460cd46

mtl pass rate lnl pass rate ptl pass rate wcl pass rate nvl pass rate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants